﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business.vo;
using Business.exception;

namespace Business.dao
{
    internal class SiteTextDao : AbstractDao
    {

        public SiteText GetById(String id)
        {
            SiteText siteText = null;

            try
            {
                siteText = mapper.QueryForObject<SiteText>("SiteText.selectById", id);

            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving site text from database", ex);
            }

            return siteText;
        }

        public IList<SiteText> GetAll()
        {
            IList<SiteText> siteText = null;

            try
            {
                siteText = mapper.QueryForList<SiteText>("SiteText.selectAll", null);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving site text from database", ex);
            }

            return siteText;
        }

        public void Save(SiteText siteText)
        {
            try
            {
                mapper.Insert("SiteText.insert", siteText);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving site text from database", ex);
            }
        }


        public void Update(SiteText siteText)
        {
            try
            {
                mapper.Update("SiteText.update", siteText);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving site text from database", ex);
            }
        }

        public void Delete(String id)
        {
            try
            {
                mapper.Delete("SiteText.deleteById", id);
            }
            catch (System.Exception ex)
            {
                log.Error(ex);
                throw new WebSiteException("Error retrieving site text from database", ex);
            }
        }
    }
}
